﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.Web.Mvc;
using Vit.Web.Mvc;
using VitData = Vit.Web.DataAnnotations;

namespace Vit.CMS.Data
{
    [MetadataType(typeof(cms_InterfaceMetadata))]
    public partial class cms_Interface
    {
    }

    public class cms_InterfaceMetadata : FilteredMetadataTypeBase<cms_Interface>
    {
        [VitData.DisplayName("Interface.Name")]
        [VitData.Required]
        public string Name { get; set; }

        public override IQueryable<cms_Interface> QueryWithFilter(IQueryable<cms_Interface> query, object filterObject)
        {
            cms_Interface obj = filterObject as cms_Interface;
            if(!string.IsNullOrEmpty(obj.Name))
                query = query.Where(o => o.Name == obj.Name);

            return query;
        }

        public override Func<cms_Interface, bool> GetEntityKeyPredict(cms_Interface obj)
        {
            return o => o.InterfaceId == obj.InterfaceId;
        }

        public override cms_Interface GetEntityWithId(string id)
        {
            return new cms_Interface() { InterfaceId = Convert.ToInt32(id) };
        }
    }

    [MetadataType(typeof(cms_DataTypeMetadata))]
    public partial class cms_DataType
    {
    }

    public class cms_DataTypeMetadata : FilteredMetadataTypeBase<cms_DataType>
    {
        [VitData.DisplayName("DataType.Name")]
        [VitData.Required]
        public string Name { get; set; }

        public override IQueryable<cms_DataType> QueryWithFilter(IQueryable<cms_DataType> query, object filterObject)
        {
            cms_Interface obj = filterObject as cms_Interface;
            return query.Where(o => o.Name == obj.Name);
        }

        public override Func<cms_DataType, bool> GetEntityKeyPredict(cms_DataType obj)
        {
            return o => o.DataTypeId == obj.DataTypeId;
        }

        public override cms_DataType GetEntityWithId(string id)
        {
            return new cms_DataType() { DataTypeId = Convert.ToInt32(id) };
        }
    }
}
